﻿@model TruckingApplication.Dal.EntityModels.ORDER

@{
	ViewBag.Title = "Create";
}

<link href="@Url.Content("~/Content/jquery-ui.css")" rel="stylesheet" type="text/css" />

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {
        //$('#dueDate').datepicker();
    });
    var d = document;
    var ctr = 0;
    function addAdvance() {

        var tbl = d.getElementById('tableMgmt');
        var lastRow = tbl.rows.length-1;
        var iteration = lastRow;
        var row = tbl.insertRow(lastRow);

        // "Advance Type"
        var idCell = row.insertCell(0);
        var textNode = d.createTextNode('Advance Type');
        idCell.appendChild(textNode);

        // <input Advance Type />
        var idCell1 = row.insertCell(1);
        var textNode1 = d.createElement('input');
        textNode1.setAttribute('id', 'advanceType_' + ctr);
        textNode1.setAttribute('name', 'advanceType_' + ctr);
        textNode1.setAttribute('type', 'text');
        textNode1.setAttribute('class', 'advanceType text-box single-line');
        idCell1.appendChild(textNode1);

        var lastRow = tbl.rows.length - 1;
        var iteration = lastRow;
        var row = tbl.insertRow(lastRow);

        // "Advance Amount"
        var idCell = row.insertCell(0);
        var textNode = d.createTextNode('Advance Amount');
        idCell.appendChild(textNode);

        // <input Advance Amount />
        var idCell1 = row.insertCell(1);
        var textNode1 = d.createElement('input');
        textNode1.setAttribute('id', 'advanceAmt_' + ctr);
        textNode1.setAttribute('name', 'advanceAmt_' + ctr);
        textNode1.setAttribute('type', 'text');
        textNode1.setAttribute('class', 'advanceAmt text-box single-line');
        idCell1.appendChild(textNode1);

        var lastRow = tbl.rows.length - 1;
        var iteration = lastRow;
        var row = tbl.insertRow(lastRow);

        // "Advance Reference #"
        var idCell = row.insertCell(0); 
        var textNode = d.createTextNode('Advance Reference #');
        idCell.appendChild(textNode);

        // <input Advance Reference # />
        var idCell1 = row.insertCell(1);
        var textNode1 = d.createElement('input');
        textNode1.setAttribute('id', 'advanceRef_' + ctr);
        textNode1.setAttribute('name', 'advanceRef_' + ctr);
        textNode1.setAttribute('type', 'text');
        textNode1.setAttribute('class', 'advanceRef text-box single-line');
        idCell1.appendChild(textNode1);

        ctr++;

        $('#orderAdvancesCount').val(ctr.toString());
    }
</script>
<br /><h2>Create New Order</h2>

@using (Html.BeginForm()) {
	@Html.ValidationSummary(true)
	<div id="lowerContainer">
		<div id="lowerContainerInner">
			<fieldset>
				<table id="tableMgmt" style="width: 100%;">
					@*<tr>
						<td>
							@Html.LabelFor(model => model.dispatcherID)
						</td>
						<td>
							@Html.DropDownList("Dispatchers", "Select One")
						</td>
					</tr>*@
					<tr>
						<td>
							@Html.LabelFor(model => model.gross)
						</td>
						<td>
							@Html.EditorFor(model => model.gross)
							@Html.ValidationMessageFor(model => model.gross)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.net)
						</td>
						<td>
							@Html.EditorFor(model => model.net)
							@Html.ValidationMessageFor(model => model.net)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.carrierRate)
						</td>
						<td>
							@Html.EditorFor(model => model.carrierRate)
							@Html.ValidationMessageFor(model => model.carrierRate)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.max)
						</td>
						<td>
							@Html.EditorFor(model => model.max)
							@Html.ValidationMessageFor(model => model.max)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.paidStatus)
						</td>
						<td>
							@Html.EditorFor(model => model.paidStatus)
							@Html.ValidationMessageFor(model => model.paidStatus)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.dueDate)
						</td>
						<td>
							@*@Html.EditorFor(model => model.dueDate)*@
                            @(Html.Kendo().DatePickerFor(model => model.dueDate).Name("dueDate").HtmlAttributes(new { style = "width:200px" }))
							@Html.ValidationMessageFor(model => model.dueDate)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.mileage)
						</td>
						<td>
							@Html.EditorFor(model => model.mileage)
							@Html.ValidationMessageFor(model => model.mileage)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.deadHeadMileage)
						</td>
						<td>
							@Html.EditorFor(model => model.deadHeadMileage)
							@Html.ValidationMessageFor(model => model.deadHeadMileage)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.quickPay)
						</td>
						<td>
							@Html.EditorFor(model => model.quickPay)
							@Html.ValidationMessageFor(model => model.quickPay)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.lumperFee)
						</td>
						<td>
							@Html.EditorFor(model => model.lumperFee)
							@Html.ValidationMessageFor(model => model.lumperFee)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.brokerID)
						</td>
						<td>
							@*@Html.DropDownList("Brokers", "Select One")*@
                            @(Html.Kendo()
                                .DropDownList()
                                .Name("Brokers")
                                .BindTo(ViewBag.Brokers as SelectList)
                                .HtmlAttributes(new { style = "width:200px" })
                            )
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.carrierID)
						</td>
						<td>
							@*@Html.DropDownList("Carriers", "Select One")*@
                            @(Html.Kendo()
                                .DropDownList()
                                .Name("Carriers")
                                .BindTo(ViewBag.Carriers as SelectList)
                                .HtmlAttributes(new { style = "width:200px" })
                            )
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.pickupCity)
						</td>
						<td>
							@Html.EditorFor(model => model.pickupCity)
							@Html.ValidationMessageFor(model => model.pickupCity)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.pickupState)
						</td>
						<td>
							@*@Html.DropDownList("PickupStates", "Select One")*@
                            @(Html.Kendo()
                                .DropDownList()
                                .Name("PickupStates")
                                .BindTo(ViewBag.PickupStates as SelectList)
                                .HtmlAttributes(new { style = "width:200px" })
                            )
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.dropOffCity)
						</td>
						<td>
							@Html.EditorFor(model => model.dropOffCity)
							@Html.ValidationMessageFor(model => model.dropOffCity)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.dropOffState)
						</td>
						<td>
							@*@Html.DropDownList("DropoffStates", "Select One")*@
                            @(Html.Kendo()
                                .DropDownList()
                                .Name("DropoffStates")
                                .BindTo(ViewBag.DropoffStates as SelectList)
                                .HtmlAttributes(new { style = "width:200px" })
                            )
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.statusID, "Order Status")
						</td>
						<td>
							@(Html.Kendo()
                                .DropDownList()
                                .Name("statusID")
                                .BindTo(ViewBag.statusID as SelectList)
                                .HtmlAttributes(new { style = "width:200px" })
                            )
							@Html.ValidationMessageFor(model => model.statusID)
						</td>
					</tr>
					<tr>
						<td>
							@Html.LabelFor(model => model.notes)
						</td>
						<td>
							@Html.TextAreaFor(model => model.notes)
							@Html.ValidationMessageFor(model => model.notes)
						</td>
					</tr>
                    <tr>
                        <td colspan="2">
                            <a href="#" onclick="addAdvance(); return false;">Add Advance</a>
                        </td>
                    </tr>
					<tr>
						<td></td>
						<td>
							<input type="submit" value="Create" class="button default btnLarge" />
						</td>
					</tr>
				</table>
			</fieldset>
            @Html.Hidden("orderAdvancesCount")
		</div>
	</div>
	}